#include "aboutUs.h"
#include <iostream>
using namespace std;
AboutUs::AboutUs()
{

    name<<"ACE"<<"LGY"<<"freelw"<<"PC_COLD"<<"forest"<<"udonmai"<<"dawn";
    index=0;
    timer.start(30);
    speed=30;
    setupUi(this);
    this->setWindowTitle(tr("关于我们"));
    startX=width();
    connect(&timer,SIGNAL(timeout()),this,SLOT(update()));
}
void AboutUs::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    int textWidth = fontMetrics().width(name.at(index));
    wd=(width()-textWidth)/2;
    painter.setPen(QPen(Qt::red,20,Qt::SolidLine,Qt::RoundCap,Qt::MiterJoin));
    painter.drawText(startX+widget->x(), widget->y()+widget->height(), textWidth, widget->height(),Qt::AlignLeft | Qt::AlignVCenter, name.at(index));
    if(startX==wd)
    {
        timer.stop();
        timer.start(2000);
        startX--;
    }
    else if(startX>wd)
    {
        if(speed>0)
        {
            speed-=5;
            timer.stop();
            timer.start(speed);
        }
        else
        {
            timer.stop();
            timer.start(1);
        }
        startX--;
    }
    else if(startX==0)
    {
        startX=width();
        speed=30;
        if(++index==4)
            index=0;
    }
    else
    {
        timer.stop();
        timer.start(1);
        startX--;
    }
}

void AboutUs::closeEvent(QCloseEvent *event)
{
    this->hide();
    timer.stop();
    event->ignore();
}

